/*
   CC.NET SideBar Gadget for Windows Vista 
   (C) Simone Chiaretta, 2007
   http://codeclimber.net.nz

   This project is licensed under the new BSD license.
   See the License.txt file for more information.
*/

var Project = function()
{
}

var Project = function(serverUrl)
{
   this.ServerUrl=serverUrl;
}

Project.prototype = 
{
   Name: "",
   
   Activity: "",
   
   Status: "",
   
   Label: "",
   
   LastBuildTime: "",
   
   NextBuildTime: "",
   
   ProjectUrl: "",
   
   NextBuildTime: "",
   
   ServerUrl: "",
   
   LastBuildUrl: "",
   
   ForceBuildUrl: "",
   
   CanForce: false,
   
   ReadFromXmlNode: function(xmlNode)
   {
      this.Name=xmlNode.getAttributeNode("name").value;
      this.Status=xmlNode.getAttributeNode("lastBuildStatus").value;
      this.ProjectUrl=xmlNode.getAttributeNode("webUrl").value;
      this.Activity=xmlNode.getAttributeNode("activity").value;
      this.Label=xmlNode.getAttributeNode("lastBuildLabel").value;
      this.LastBuildTime=xmlNode.getAttributeNode("lastBuildTime").value;
      this.NextBuildTime=xmlNode.getAttributeNode("nextBuildTime").value;
      this.BuildUrls();
   },
   
   BuildUrls: function()
   {
	  var regExStr = "/server/(.*)/project/(.*)/";
	  var regex = new RegExp(regExStr);
	  var matches = regex.exec(this.ProjectUrl);
	  
	  if(matches != null)
	  {
		  
		  var serverName=RegExp.$1;
		  var projectName=RegExp.$2;
		  
		  if(projectName!=this.Name)
			return;
			
		  this.CanForce = true;
		  
		  var projectUrl = this.ServerUrl + "server/" + serverName + "/project/" + projectName + "/";
		  
		  this.ForceBuildUrl = projectUrl + "ForceBuild.aspx";
		  this.LastBuildUrl = projectUrl + "ViewLatestBuildReport.aspx";
      }
   }
}